Contents

  1. You want to do what?!?
  2. Getting started
  3. The desktop
  4. A pseudo-base class
  5. Joy and grief
  6. Timing is everything (or sometimes nothing)
  7. Conclusions / Lessons Learned

Menu Item Flashing

This works marginally okay under 95, but not under NT, where the painting occurs all at once without a noticeable delay. Threads didn't help, and may incur too much overhead while setting up. Swing (JFC) has a Timer class that looks cool, as long as the setup overhead is minimal.
	public void doFlashMenuItem( DesktopMenu d ) {
		Graphics g = this.getGraphics();

		if ( ( this.activeMenu != -1 ) && ( this.activeMenuItem != -1 ) ) {
			// Get menu item vector.
			Vector v = d.getVector();

			// Flash three times.
			for ( int i = 0; i < 3; i++ ) {
				// Redraw menu background behind this menu item.
				g.setColor( dmb.getBackground() );
				g.fillRect( activeMenuItemRect.x, activeMenuItemRect.y, activeMenuItemRect.width, activeMenuItemRect.height );

				g.setColor( Color.black );
				g.drawRect( d.getItemBounds().getBounds().x, d.getItemBounds().getBounds().y, d.getItemBounds().getBounds().width, d.getItemBounds().getBounds().height );

				// Redraw menu item.
				g.setColor( Color.black );
				g.drawString( ( ( DesktopMenuItem )v.elementAt( activeMenuItem ) ).getLabel(), ( ( DesktopMenuItem )v.elementAt( activeMenuItem ) ).getDrawPoint().x, ( ( DesktopMenuItem )v.elementAt( activeMenuItem ) ).getDrawPoint().y );

				this.doMenuDelay();

				// Redraw menu background behind this menu item.
				g.setColor( Color.blue );
				g.fillRect( activeMenuItemRect.x, activeMenuItemRect.y, activeMenuItemRect.width, activeMenuItemRect.height );

				g.setColor( Color.black );
				g.drawRect( d.getItemBounds().getBounds().x, d.getItemBounds().getBounds().y, d.getItemBounds().getBounds().width, d.getItemBounds().getBounds().height );

				// Redraw menu item.
				g.setColor( Color.white );
				g.drawString( ( ( DesktopMenuItem )v.elementAt( activeMenuItem ) ).getLabel(), ( ( DesktopMenuItem )v.elementAt( activeMenuItem ) ).getDrawPoint().x, ( ( DesktopMenuItem )v.elementAt( activeMenuItem ) ).getDrawPoint().y );

				this.doMenuDelay();
			}
		}
	}

	public void doMenuDelay() {
		Calendar c = Calendar.getInstance();
		Calendar old = Calendar.getInstance();

		// Set the completion time.
		old.add( Calendar.MILLISECOND, Global.menuDelayMillis );

		// Loop until the time has passed.
		while ( !c.after( old ) ) {
			c = Calendar.getInstance();
		}
	}
	
PreviousNext